package tmp;

/**
 * Created by dycong on 2017/4/25.
 */
public class MyThreadLocal1 {
    private static final ThreadLocal<Integer> local = new ThreadLocal<Integer>();

    public static void main(String[] args) {
        Thread[] threads = new Thread[5];
        for (int i = 0; i < 5; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    Integer integer = Integer.valueOf(0);
                    for (int j = 0; j < 5; j++)
                        integer++;
                    local.set(integer);
                    System.out.println(Thread.currentThread()+"-"+local.get());
                }
            });
        }
        for (Thread thread : threads) {
            thread.start();
        }
    }

}
